from multiprocessing import Process
import os
import time
def sub_p1(name):
    print(f"子进程pid是：{os.getpid()},父进程的pid是：{os.getppid()}", name)
    time.sleep(1)
def sub_p2(name):
    print(f"子进程pid是：{os.getpid()},父进程的pid是：{os.getppid()}", name)
    time.sleep(1)

if __name__ == '__main__':
    # 主进程
    print("主进程开始执行")
    for i in range(5):
        # 创建子进程
        p1 = Process(target=sub_p1, args=("q",))
        p2 = Process(target=sub_p2, args=("w", ))
        p1.start()
        p2.start()
        # 强制终止进程
        p1.terminate()
        p2.terminate()
    print("主线程执行完毕")